/*
 * gy_enplisten.cpp
 *
 *  Created on: 2015年9月15日
 *      Author: gaoyi
 */




#include "gy_enplisten.h"
#include "gy_enpctrl.h"

int GYEnpListen::Init(GYEnpCtrl &stOwner, const char *pszIPAddr, unsigned short ushPort)
{
	m_pstOwner = &stOwner;
	m_stListenInfo.m_szListenIP = pszIPAddr;
	m_stListenInfo.m_unListenPort = ushPort;
	m_stListenInfo.m_stPackageType = enp_package_protobuf;
	m_stListenInfo.m_ucDecodeMethod = CODE_PROTOBUF;
	m_stListenInfo.m_ucEncodeMethod = CODE_PROTOBUF;

	int iRet = 0;
	iRet = m_stSocket.Listen(pszIPAddr, ushPort);
	CHECK_RETURN(iRet);

	iRet = Register(stOwner, &GYEnpCtrl::OnListenEvent, stOwner.m_stEpoll, m_stSocket.GetSocket(), EPOLLIN);
	CHECK_RETURN(iRet);

	return 0;
}
